import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * @creationDate 2019/12/25
 */
import request from "../../utils/request";
import { getEnvConfig } from "../../utils/iocUtils";
import { getCurrentOrganizationId } from "../../utils/utils";

var _getEnvConfig = getEnvConfig(),
    CPAAS_MSG = _getEnvConfig.CPAAS_MSG;
/**
 * 查询未读的站内消息
 * {CPAAS_MSG}/v1/{organizationId}/messages/user/preview
 * @export
 * @param {object} params
 */


export function queryNotices(_x) {
  return _queryNotices.apply(this, arguments);
}
/**
 * 查询未读的站内公告
 * {CPAAS_MSG}/v1/{organizationId}/notices/user/preview
 * @export
 * @param {object} params
 */

function _queryNotices() {
  _queryNotices = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context.abrupt("return", request("".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/messages/user/preview"), {
              method: 'GET',
              query: params
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryNotices.apply(this, arguments);
}

export function queryAnnounces(_x2) {
  return _queryAnnounces.apply(this, arguments);
}
/**
 * 查询站内消息条数
 * {CPAAS_MSG}/v1/{organizationId}/messages/user/count
 * @export
 */

function _queryAnnounces() {
  _queryAnnounces = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context2.abrupt("return", request("".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/notices/user/preview"), {
              method: 'GET',
              query: params
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _queryAnnounces.apply(this, arguments);
}

export function queryCount() {
  return _queryCount.apply(this, arguments);
}
/**
 * 已读全部消息
 * {CPAAS_MSG}/v1/${organizationId}/messages/user/read-flag
 * @export
 */

function _queryCount() {
  _queryCount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context3.abrupt("return", request("".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/messages/user/count"), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _queryCount.apply(this, arguments);
}

export function allRead(_x3) {
  return _allRead.apply(this, arguments);
}
/**
 * 删除全部消息
 * {CPAAS_MSG}/v1/${organizationId}/messages/user/clear
 * @export
 */

function _allRead() {
  _allRead = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context4.abrupt("return", request("".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/messages/user/read-flag"), {
              method: 'POST',
              query: params
            }));

          case 2:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _allRead.apply(this, arguments);
}

export function deleteAll() {
  return _deleteAll.apply(this, arguments);
}

function _deleteAll() {
  _deleteAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context5.abrupt("return", request("".concat(CPAAS_MSG, "/v1/").concat(organizationId, "/messages/user/clear"), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _deleteAll.apply(this, arguments);
}